﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mscook.core.components
{
    public abstract class AbstractBonusStrategy
    {

        protected abstract bool IfNeedBonus();

        protected abstract int GetAvailableBonus();

        protected abstract bool UpdateUserBonus(int bonus);
        protected abstract bool UpdateUserBonus(int bonus,int num);

        public abstract bool CheckEnoughBonus();
        public abstract bool CheckEnoughBonus(int num);


        public bool SetBonus()
        {
            if (IfNeedBonus())
            {
                int bonus = GetAvailableBonus();//获取相应动作或者资源的积分
                if (CheckEnoughBonus())
                {
                    return UpdateUserBonus(bonus);
                }
                return false;
            }
            else
            {
                return true;
            }
        }

        public bool SetBonus(bool isNeedBonus,int num)
        {
            if (isNeedBonus)
            {
                int bonus = GetAvailableBonus();//获取资源设置积分
                if (CheckEnoughBonus(num))
                {
                    return UpdateUserBonus(bonus,num);
                }
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
